using System;
using AutoMapper;
using PhoneBook.Core.Domain.Contacts;
using PhoneBook.Core.Domain.Phones;
using PhoneBook.Core.Domain.UserGroups;
using PhoneBook.Models.Contacts;
using PhoneBook.Models.Phones;
using PhoneBook.Models.UserGroups;

namespace PhoneBook
{
    public class AutoMapperConfigure
    {
        
        public static  void Configure()
        {
            //contact add or edit
            Mapper.CreateMap<Contact, ContactAddOrEditModel>().ForMember(d => d.ContactId,
                                                                        opt => opt.MapFrom(s => s.Id));

            Mapper.CreateMap<ContactAddOrEditModel, Contact>().ForMember(d => d.Id,
                                                                      opt => opt.MapFrom(s => s.ContactId));
            Mapper.CreateMap<Contact, ContactListModel>();



            //user group
            Mapper.CreateMap<UserGroup, UserGroupAddOrEditModel>().ForMember(d => d.GroupId,
                                                               opt => opt.MapFrom(s => s.Id));


            Mapper.CreateMap<UserGroupAddOrEditModel, UserGroup>().ForMember(d => d.Id,
                                                                        opt => opt.MapFrom(s => s.GroupId));

            Mapper.CreateMap<UserGroup, UserGroupListModel>().ForMember(d => d.UserGroupId,
                                                                        opt => opt.MapFrom(s => s.Id));

            //phone
            Mapper.CreateMap<Phone, PhoneAddOrEditModel>();

          
            Mapper.CreateMap<PhoneAddOrEditModel, Phone>().ForMember(d => d.PhoneType,
                                                             opt => opt.MapFrom(s => Enum.Parse(typeof(PhoneType), s.SelectedPhoneType)));

            Mapper.CreateMap<Phone, PhoneListModel>();



        }
    }
}